define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'editable'], function ($, undefined, Backend, Table, Form, undefined) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'feditionaccountfb/index' + location.search,
                    add_url: 'feditionaccountfb/add',
                    edit_url: 'feditionaccountfb/edit',
                    del_url: 'feditionaccountfb/del',
                    multi_url: 'feditionaccountfb/multi',
                    import_url: 'feditionaccountfb/import',
                    table: 'fedition_accountfb',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                pageSize: 20,
                search: false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'admin_id', title: __('Admin_id'),visible: false,addClass: "selectpage", extend: "data-source='auth/admin/index' data-field='nickname'"},
                        {field: 'admin_name', title: __('Admin_id'), operate: false},
                        // {field: 'id', title: __('Id')},
                        // {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},

                        {field: 'username', title: __('Username'), operate: 'LIKE'},
                        {field: 'password', title: __('Password'), operate: 'LIKE'},
                        {field: 'code', title: __('Code'), operate: 'LIKE'},
                        {field: 'email', title: __('Email'), operate: 'LIKE'},
                        {field: 'info', title: __('备注'), operate: false,
                            editable: {
                                type: "textarea",
                                title: "填写备注",
                                disabled: false,
                                emptytext: "请填写",
                                mode: "popup",
                                validate: function (value) { //字段验证
                                    if (!$.trim(value)) {
                                        return '不能为空';
                                    }
                                }
                            },
                            cellStyle: function () {
                                return{
                                    css: {
                                        "max-width":"400px",
                                        "text-overflow": "ellipsis",
                                        "white-space": "initial"
                                    }
                                };
                            }
                        },

                        // {field: 'secretvalue', title: __('Secretvalue'), operate: 'LIKE'},
                        {field: 'status', title: __('Status'), searchList: {"normal":__('养号中'),"hidden":__('未启用'),"distribution":__('已分配')}, formatter: Table.api.formatter.status,custom: {normal:'warning', hidden:'danger', distribution:'success'}},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});